package com.bingo.generate.cli;

import com.bingo.generate.cli.args.CliParam;
import com.bingo.generate.cli.lccmd.OldBaseCmd;
import com.bingo.generate.cli.lccmd.OldExitCmd;
import com.bingo.generate.cli.lccmd.OldGenerateDb;
import picocli.CommandLine;

import java.time.LocalDateTime;
import java.util.Scanner;

/**
 * ClassName
 * Description
 * Create by lc
 * Date 2021/7/9 15:54
 */
public class OldUse {

    public static final Scanner sc=new Scanner(System.in);

    //  java -classpath .; com/bingo/generate/Use
    public static void main(String[] args) {
        useCmd();
        //useCli(args);
    }

    public static void useCmd() {
        System.out.println("欢迎使用灵冲.银河之舰版本:");
        System.out.println("当前使用时间:"+ LocalDateTime.now().toString());
        System.out.println("-每日一思:");
        System.out.println("--风萧萧兮易水寒,壮士一去兮不复还");
        //  加载命令
        {
            /*List<Class> list = BaseUtil.getAllCla("com.bingo.generate");
            for (Class aClass : list) {
                if(aClass== BaseCmd.class){
                    continue;
                }
                System.out.println("动态插拔命令");
                try {
                    Object obj = aClass.newInstance();
                    BaseCmd.addCmd(obj);
                } catch (InstantiationException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }*/
            OldBaseCmd.addCmd(new OldGenerateDb());
            OldBaseCmd.addCmd(new OldExitCmd());
        }

        while (true){
            System.out.println("可以使用命令如下:");
            for (int i = 0; i < OldBaseCmd.list.size(); i++) {
                System.out.println("- "+i+"."+ OldBaseCmd.list.get(i).getName());
            }

            int ret = sc.nextInt();
            if(ret<0||ret>= OldBaseCmd.list.size()){
                System.out.println("你输入的值:"+ret+" 超出了选择范围.");
                continue;
            }
            System.out.println("你输入的值:"+ret+" ,选择了"+ OldBaseCmd.list.get(ret).getName());
            OldBaseCmd.list.get(ret).handler();
            System.out.println();
        }


    }

    public static void useCli(String[] args){
        // 解析参数
        final CliParam CliParam = new CliParam();
        final CommandLine commandLine = new CommandLine(CliParam);
        try {
            final CommandLine.ParseResult parseResult = commandLine.parseArgs(args);
            if (parseResult.isUsageHelpRequested()) {
                commandLine.usage(System.out);
                System.exit(0);
            }
            if (parseResult.isVersionHelpRequested()) {
                commandLine.printVersionHelp(System.out);
                System.exit(0);
            }
            CliParam.setINSTANCE(CliParam);
        } catch (CommandLine.ParameterException e) {
            commandLine.usage(System.out);
            System.exit(1);
        }
    }

}
